﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MSHTML = mshtml;
using Helpers.Conditions;
using Helpers;

namespace HtmlParsing.Helpers.Conditions
{
    public class BaseTagCondition<T> : BaseCondition<T>
    {
        public virtual string Id { get; set; }
        public virtual string Name { get; set; }

        public override bool IsAccepted(T tag)
        {
            MSHTML.IHTMLElement element = tag as MSHTML.IHTMLElement;

            if (element == null)
                throw new Exception("Wrong element type");

            bool result = true;

            result &= StringHelper.IsnullOrBlank(Id)
                || (element.getAttribute("Id", 0) != null
                    && element.getAttribute("Id", 0).ToString().ToUpper() == Id.ToUpper());

            result &= StringHelper.IsnullOrBlank(Id)
                || (element.getAttribute("Name", 0) != null
                    && element.getAttribute("Name", 0).ToString().ToUpper() == Id.ToUpper());

            return result;
        }
    }
}
